/*
 * Copyright (c) 2011. c.mueller
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * The Software shall be used for Good, not Evil.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package de.altitude.cimuelle.coop;

import de.altitude.cimuelle.player.PlayerConfiguration;
import de.altitudecustomcommands.Player;

import java.io.Serializable;

/**
 * Class description:
 * an CoopPlayer object with stats and values
 * User: cybernaut
 * Date: 07.10.11
 * Time: 15:30
 */
public class CoopPlayer implements Serializable {

    private static final long serialVersionUID = 1000400001L;

    private final String vapor;
    private String name = "";
    private int playerId = -1;

    private PlayerConfiguration playerConfiguration;

    private final CoopPlayerStats stats;

    private boolean isAlive = false;

    private long diedAfterSeconds = -1;

    private boolean spawned = false;
    private boolean destroyedBase = false;
    private int coopPoints = 0;
    private boolean leftBeforeDie = false;


    public CoopPlayer(Player player) {
        // Called by spawning
        this.vapor = player.getVapor();
        this.name = player.getName();
        this.playerId = player.getPlayerNumber();
        this.isAlive = true;
        this.spawned = true;

        this.playerConfiguration = player.getPlayerConfiguration();
        this.stats = new CoopPlayerStats();
    }

    public String getVapor() {
        return vapor;
    }

    public String getName() {
        return name;
    }

    public boolean isAlive() {
        return isAlive;
    }

    public void setAlive(boolean alive) {
        isAlive = alive;
    }

    public boolean isDestroyedBase() {
        return destroyedBase;
    }

    public void setDestroyedBase(boolean destroyedBase) {
        this.destroyedBase = destroyedBase;
    }

    public long getDiedAfterSeconds() {
        return diedAfterSeconds;
    }

    public void setDiedAfterSeconds(long diedAfterSeconds) {
        this.diedAfterSeconds = diedAfterSeconds;
    }


    @Override
    public String toString() {
        return "CoopPlayer{" +
                "vapor='" + vapor + '\'' +
                ", name='" + name + '\'' +
                ", playerId=" + playerId +
                ", playerConfiguration=" + playerConfiguration +
                ", stats=" + stats +
                ", isAlive=" + isAlive +
                ", diedAfterSeconds=" + diedAfterSeconds +
                ", spawned=" + spawned +
                ", destroyedBase=" + destroyedBase +
                ", coopPoints=" + coopPoints +
                '}';
    }

    public void addCoopPts(int coopPoints) {
        this.coopPoints = this.coopPoints + coopPoints;
    }

    public int getCoopPoints() {
        return coopPoints;
    }

    public void addTurretKill() {
        stats.setTurretsDestroyed(stats.getTurretsDestroyed() + 1);
    }

    public int getTurretKills() {
        return stats.getTurretsDestroyed();
    }

    public PlayerConfiguration getPlayerConfiguration() {
        return playerConfiguration;
    }

    public int getPlayerId() {
        return playerId;
    }

    public void setLeftBeforeDie(boolean leftBeforeDie) {
        this.leftBeforeDie = leftBeforeDie;
    }

    public boolean isLeftBeforeDie() {
        return leftBeforeDie;
    }
}
